package com.yuanfengerp.Analysis.service.impl;
import com.yuanfengerp.Analysis.dao.IRolePipeDao;
import com.yuanfengerp.Analysis.model.RolePipe;
import com.yuanfengerp.Analysis.service.IRolePipeService;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

@Service
public class IRolePipeServiceImpl implements IRolePipeService {
    @Autowired
    private IRolePipeDao irpd;

    /**
     *  添加角色
     * @param rolePipe
     * @return
     */
    @Override
    public Result<RolePipe> addRolePipe(RolePipe rolePipe) {
//        if(rolePipe.getRole_serial() == 0){
//            return Result.failure(400,"角色编号不能为空");
//        }
//        if(rolePipe.getRole_name() == null){
//            return Result.failure(400,"角色名称不能为空");
//        }
        rolePipe.setRole_create_time(new Date());
        rolePipe.setRole_modification_time(new Date());
        int i = irpd.addRolePipe(rolePipe);
        return i==1? Result.success(rolePipe):Result.failure(400,"添加失败");
    }
    /**
     *  根据角色编号和角色名称查询角色
     * @param role_serial
     * @param role_name
     * @return
     */
    @Override
    public Result<RolePipe> getRolePipe(String role_serial, String role_name) {
        ArrayList<RolePipe> RolePipes = irpd.getRolePipeByRole_serialAndRole_name(role_serial,role_name);
        return RolePipes.size() == 0? Result.failure(400,"没有数据") : Result.success(RolePipes.get(0));
    }

    @Override
    public ArrayList<RolePipe> getRolePipeList(Integer pageSize, Integer offset) {
        ArrayList<RolePipe> RolePipes = irpd.getRolePipe(pageSize ,offset);
        return RolePipes;
    }

    @Override
    public Result<RolePipe> updateRolePipe(RolePipe rolePipe) {
        rolePipe.setRole_modification_time(new Date());
        int i = irpd.updateRolePipe(rolePipe);
        return i > 0 ? Result.success(rolePipe) : Result.failure(400,"修改失败");
    }
}
